#include<iostream>
#include<vector>
#include<string>

using namespace std;

class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int left = 0, right = nums.size() - 1;
        while (left < right) {
            int mid = (left + right) / 2;
            if (nums[mid] == target)
                return mid;
            else if (nums[mid] > target)
                right = mid-1;
            else left = mid+1;
        }
        if (nums[left] == target)
            return left;
        else if (nums[left] > target) {
            nums.insert(nums.begin() + left, target);
            return left;
        }
        else {
            nums.insert(nums.begin() + left+1, target);
            return left + 1;
        }
    }
};

int main() {
    vector<int> nums = { 1,3 };
    Solution s;
    s.searchInsert(nums, 0);
    return 0;
}